<template>
  <page-table
    rowKey="name"
    ref="generatorPageTable"
    query-type="list"
    :query-api="table_queryListColumnApi"
    :columns="columns"
    :query-param="queryParam"
    :toolBar="[]"
    :showAddButton="false"
    :showDeleteButton="false"
    :selection="null"
  >
    <template #customComment="{record}">
      <a-input v-model="record.comment" />
    </template>
    <template #customQueryType="{record}">
      <dictionary-select codeItemId="CREATE_QUERY_TYPE" v-model="record.queryType"></dictionary-select>
    </template>
    <template #customShowTable="{record}">
      <a-switch v-model="record.showTable" />
    </template>
    <template #customShowForm="{record}">
      <dictionary-select codeItemId="CREATE_SHOW_FORM_TYPE" v-model="record.showForm"></dictionary-select>
    </template>
    <template #customRequired="{record}">
      <a-checkbox v-model="record.required" />
    </template>
    <template #customDictionaryType="{record}">
      <query-dictionary v-model="record.dictionaryTypeId" />
    </template>
  </page-table>
</template>

<script>
import { table_queryListColumnApi } from "@/api/generator/table";
import QueryDictionary from "@/views/cms/generator/component/queryDictionary";
//定义列表数据
const columns = [
  {
    title: "名称",
    dataIndex: "name",
    width: "200px"
  },
  {
    title: "类型",
    dataIndex: "columnType",
    width: "150px"
  },
  {
    title: "字段标题",
    dataIndex: "comment",
    scopedSlots: { customRender: "customComment" }
  },
  {
    title: "查询方式",
    width: "200px",
    scopedSlots: { customRender: "customQueryType" }
  },
  {
    title: "列表显示",
    dataIndex: "showTable",
    width: "100px",
    align: "center",
    scopedSlots: { customRender: "customShowTable" }
  },
  {
    title: "表单显示",
    dataIndex: "showForm",
    width: "200px",
    scopedSlots: { customRender: "customShowForm" }
  },
  {
    title: "是否必填",
    dataIndex: "required",
    width: "100px",
    align: "center",
    scopedSlots: { customRender: "customRequired" }
  },
  {
    title: "数据字典",
    dataIndex: "dictionaryTypeId",
    width: "260px",
    align: "center",
    scopedSlots: { customRender: "customDictionaryType" }
  }
];
export default {
  components: { QueryDictionary },
  props: {
    tableName: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      table_queryListColumnApi,
      columns,
      queryParam: {
        tableName: this.tableName
      }
    };
  },
  methods: {
    getColums() {
      return this.$refs.generatorPageTable.getDataSource();
    }
  }
};
</script>